﻿
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.SANY.Util;

namespace PMS.SANY.Entity
{
    /// <summary>
    /// 生产工位
    /// </summary>
    public partial class WorkshoStation : BusEntity
    {
        /// <summary>
        /// 生产单元ID
        /// </summary>
        public string UnitId { set; get; }
        /// <summary>
        /// 工序ID
        /// </summary>
        public string ProcessId { get; set; }
        /// <summary>
        /// 生产工位编码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 生产工位名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 工位类型(CF_Enum.Code=StationType)
        /// </summary>
        public string Type { set; get; }
    }

    public partial class WorkshoStation : BusEntity
    {
        /// <summary>
        /// 所属生产单元
        /// </summary>
        public WorkshoUnit Unit { set; get; }
        /// <summary>
        /// 所属工序
        /// </summary>
        public CraftStepProcess Process { set; get; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class WorkshoStationTypeConfig : BusEntityTypeConfig<WorkshoStation>, IEntityTypeConfiguration<WorkshoStation>
    {
        public override void Configure(EntityTypeBuilder<WorkshoStation> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Unit).WithMany(p => p.Stations).HasForeignKey(p => p.UnitId);
            builder.HasOne(p => p.Process).WithMany(p => p.Stations).HasForeignKey(p => p.ProcessId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.UnitId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.ProcessId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Code).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Type).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            #endregion

            #region 备注
            builder.HasComment("生产工位");
            builder.Property(p => p.UnitId).HasComment("生产单元ID");
            builder.Property(p => p.ProcessId).HasComment("工序ID");
            builder.Property(p => p.Code).HasComment("生产工位编码");
            builder.Property(p => p.Name).HasComment("生产工位名称");
            builder.Property(p => p.Type).HasComment("工位类型(CF_Enum.Code=StationType)");
            #endregion

            #region 种子数据
            builder.HasData(new WorkshoStation() { Id = "3505JB01A0010", Code = "3505JB01A0010", UnitId = "550182", ProcessId = "0010", Name = "球冠压入工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "3505CX01A0010", Code = "3505CX01A0010", UnitId = "550256", ProcessId = "0010", Name = "耐磨条堆焊工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "3505FH02A0010", Code = "3505FH02A0010", UnitId = "550221", ProcessId = "0010", Name = "拼板焊接工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "3505FH01A0010", Code = "3505FH01A0010", UnitId = "550193", ProcessId = "0010", Name = "球冠焊接工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new WorkshoStation() { Id = "3505JB01A0021", Code = "3505JB01A0021", UnitId = "550185", ProcessId = "0020", Name = "立式组对1#工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "3505JB01A0022", Code = "3505JB01A0022", UnitId = "550185", ProcessId = "0020", Name = "立式组对2#工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "3505CX01A0011", Code = "3505CX01A0011", UnitId = "550257", ProcessId = "0020", Name = "油压成型工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            
            builder.HasData(new WorkshoStation() { Id = "3505JB01A0031", Code = "3505JB01A0031", UnitId = "550186", ProcessId = "0030", Name = "内环焊1#工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "3505JB01A0032", Code = "3505JB01A0032", UnitId = "550186", ProcessId = "0030", Name = "内环焊2#工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "3505FH02A0030", Code = "3505FH02A0030", UnitId = "550222", ProcessId = "0030", Name = "纵焊工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            
            builder.HasData(new WorkshoStation() { Id = "3505JB01A0041", Code = "3505JB01A0041", UnitId = "550187", ProcessId = "0040", Name = "叶片摆搭1#工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "3505JB01A0042", Code = "3505JB01A0042", UnitId = "550187", ProcessId = "0040", Name = "叶片摆搭2#工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "3505JB01A0043", Code = "3505JB01A0043", UnitId = "550187", ProcessId = "0040", Name = "叶片摆搭3#工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
           
            builder.HasData(new WorkshoStation() { Id = "3505JB01A0051", Code = "3505JB01A0051", UnitId = "550188", ProcessId = "0050", Name = "叶片满焊1#工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "3505JB01A0052", Code = "3505JB01A0052", UnitId = "550188", ProcessId = "0050", Name = "叶片满焊2#工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "3505JB01A0053", Code = "3505JB01A0053", UnitId = "550188", ProcessId = "0050", Name = "叶片满焊3#工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "3505JB01A0054", Code = "3505JB01A0054", UnitId = "550188", ProcessId = "0050", Name = "叶片满焊4#工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            
            builder.HasData(new WorkshoStation() { Id = "3505JB01A0061", Code = "3505JB01A0061", UnitId = "550189", ProcessId = "0060", Name = "合模1#工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "3505JB01A0062", Code = "3505JB01A0062", UnitId = "550189", ProcessId = "0060", Name = "合模2#工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            
            builder.HasData(new WorkshoStation() { Id = "3505JB01A0081", Code = "3505JB01A0081", UnitId = "550191", ProcessId = "0080", Name = "环焊1#工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "3505JB01A0082", Code = "3505JB01A0082", UnitId = "550191", ProcessId = "0080", Name = "环焊2#工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoStation() { Id = "3505JB01A0083", Code = "3505JB01A0083", UnitId = "550191", ProcessId = "0080", Name = "环焊3#工位", Type = "Automatic", CreateUserId = "1", ModifyUserId = "1" });
            #endregion
        }
    }
}
